/**
 * @Description 更新单位申请隔离人员名单的中审批时间字段
 * @author WU LiHua
 * @date 2020年2月8日 下午3:35:45
 */
package com.awspaas.user.apps.shhtaerospaceindustrial.extbutton;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListenerInterface;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.service.util.ModelUtil;

import java.util.List;
import java.util.Map;

public class UpdateUnitGeLiPsnSpDate extends ExecuteListener implements ExecuteListenerInterface {

	@Override
	public String getDescription() {
		return "更新单位申请隔离人员名单的中审批时间字段";
	}

	@Override
	public void execute(ProcessExecutionContext pec) throws Exception {
		try {
			boolean flag_company_ok = SDK.getTaskAPI().isChoiceActionMenu(pec.getTaskInstance(), "同意");
			if (flag_company_ok) {
				String bindId = pec.getProcessInstance().getId();// 流程实例ID
				List<BO> ceitemlist = SDK.getBOAPI().query("BO_EU_SHHT_SPFGRY_MX", true).addQuery("BINDID =", bindId)
						.asc().list();

				if (ceitemlist != null && !ceitemlist.isEmpty()) {
					for (int i = 0; i < ceitemlist.size(); i++) {
						BO ceitembo = ceitemlist.get(i);
						Map<String, Object> record = ceitembo.asMap();
						record.put("SPRETURNDATE", SDK.getRuleAPI().executeAtScript("@date"));
						int updateflag = SDK.getBOAPI().update("BO_EU_SHHT_SPFGRY_MX", ModelUtil.toModel(record));

					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static String objToStr(Object obj) {
		return obj == null ? "" : obj.toString();
	}
}
